﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System.Windows;
using System.Windows.Media.Animation;

namespace Xceed.Silverlight.ListBox
{
  internal class RotateAnimation : DependencyObject, IAnimation
  {
    #region AngleChange Property

    internal static readonly DependencyProperty AngleChangeProperty = DependencyProperty.Register(
      "AngleChange",
      typeof( double ),
      typeof( RotateAnimation ),
      new PropertyMetadata( ( double )0.0d ) );

    internal double AngleChange
    {
      get
      {
        return ( double )this.GetValue( RotateAnimation.AngleChangeProperty );
      }
      set
      {
        this.SetValue( RotateAnimation.AngleChangeProperty, value );
      }
    }

    #endregion

    #region ActualAngleChange Property

    internal static readonly DependencyProperty ActualAngleChangeProperty = DependencyProperty.Register(
      "ActualAngleChange",
      typeof( double ),
      typeof( RotateAnimation ),
      new PropertyMetadata( ( double )0.0 ) );

    internal double ActualAngleChange
    {
      get
      {
        return ( double )this.GetValue( RotateAnimation.ActualAngleChangeProperty );
      }
      set
      {
        this.SetValue( RotateAnimation.ActualAngleChangeProperty, value );
      }
    }

    #endregion

    #region IAnimation Members

    AnimationDirection IAnimation.AnimationDirection
    {
      get;
      set;
    }


    IEasingFunction IAnimation.EasingFunction
    {
      get
      {
        return m_easingFunction;
      }
      set
      {
        if( m_easingFunction != value )
        {
          m_easingFunction = value;
        }
      }
    }

    TransitionAnimation IAnimation.ParentTransition
    {
      get
      {
        return m_parentTransition;
      }
      set
      {
        if( m_parentTransition != value )
        {
          m_parentTransition = value;
        }
      }
    }

    void IAnimation.ComputeAnimationUpdate( double normalizedTime )
    {
      double easedTime = normalizedTime;
      if( m_easingFunction != null )
      {
        easedTime = m_easingFunction.Ease( normalizedTime );
      }

      if( !double.IsNaN( this.AngleChange ) )
      {
        this.ActualAngleChange = this.AngleChange - ( easedTime * this.AngleChange );
      }
    }

    #endregion

    #region Private Members

    private TransitionAnimation m_parentTransition = null;
    private IEasingFunction m_easingFunction = null;

    #endregion
  }
}
